import { defineConfig, loadEnv } from 'vite';
import { plugins, css, build, server, resolve, optimizeDeps } from './build/index';

export default ({ mode }) => {
	// 环境变量
	const env = loadEnv(mode, process.cwd());
	// 生产环境判断
	const isProduction = mode === 'production';

	return defineConfig({
		resolve: resolve(isProduction),
		optimizeDeps,
		// 基础路径，配合vue-router的createWebHashHistory使用
		base: isProduction ? '/' : './',
		plugins: plugins(isProduction, env),
		css,
		build,
		server: server(env),
	});
};
